<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="12">
			<p-form-item label="排班日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择排班日期" v-decorator="[ 'layoutTime', validatorRules.layoutTime]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="班次" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['layoutClasses', validatorRules.layoutClasses]" :trigger-change="true" dictCode="mes_layout_classes" placeholder="请选择班次"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="排班状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['layoutState', validatorRules.layoutState]" :trigger-change="true" dictCode="mes_layout_state" placeholder="请选择排班状态"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="班组" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'layoutGroup', validatorRules.layoutGroup]" placeholder="请输入班组"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="线体编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['lineno', validatorRules.lineno]"
						:trigger-change="true"
						org-fields="lineid,lineno,linename"
						dest-fields="lineid,lineno,linename"
						code="line_select"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="线体名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'linename', validatorRules.linename]" placeholder="请输入线体名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="人力需求" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'layoutManpower', validatorRules.layoutManpower]" placeholder="请输入人力需求" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="在职人数" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'layoutBethe', validatorRules.layoutBethe]" placeholder="请输入在职人数" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="排配人数" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'layoutSteak', validatorRules.layoutSteak]" placeholder="请输入排配人数" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="实到人数" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'layoutTrue', validatorRules.layoutTrue]" placeholder="请输入实到人数" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="借用人数" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'layoutBorrow', validatorRules.layoutBorrow]" placeholder="请输入借用人数" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="差额" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'layoutBalance', validatorRules.layoutBalance]" placeholder="请输入差额" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'remark', validatorRules.remark]" placeholder="请输入备注"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>


  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesMfProductionLayoutModal",
	mixins: [SubmitOnchangMixin],
    components: { 
      JDate,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        layoutTime:{rules: [{ required: true, message: '请输入排班日期!' }]},
        layoutClasses:{rules: [{ required: true, message: '请输入班次!' }]},
        layoutState:{rules: [{ required: true, message: '请输入排班状态!' }]},
        layoutGroup:{},
        lineno:{rules: [{ required: true, message: '请输入线体编码!' }]},
        linename:{},
        layoutManpower:{},
        layoutBethe:{},
        layoutSteak:{},
        layoutTrue:{},
        layoutBorrow:{},
        layoutBalance:{},
        remark:{},
        },
        url: {
          add: '/mes-manufacture/auto/mesMfProductionLayout/add',
          edit: '/mes-manufacture/auto/mesMfProductionLayout/edit',
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'layoutTime','layoutClasses','layoutState','layoutGroup','lineno','linename','layoutManpower','layoutBethe','layoutSteak','layoutTrue','layoutBorrow','layoutBalance','createBy','createTime','updateBy','updateTime','remark'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'layoutTime','layoutClasses','layoutState','layoutGroup','lineno','linename','layoutManpower','layoutBethe','layoutSteak','layoutTrue','layoutBorrow','layoutBalance','createBy','createTime','updateBy','updateTime','remark'))
      },

      
    }
  }
</script>
